package 力扣日常刷题.木23一月.第18天318;

import java.util.Arrays;

public class Demo92最长回文子串 {


    public String longestPalindrome(String s) {
        int n = s.length();
        boolean[][] dp = new boolean[n][n];
        for(int i = 0; i < n; i ++){
            Arrays.fill(dp[i],true);
        }


        int maxLen = 1,begin = 0;

        for (int i = n - 1; i >= 0; i--) {
            for (int j = i+1; j < n; j++) {
                dp[i][j] = (s.charAt(i) == s.charAt(j)) && dp[i+1][j - 1];
                if(dp[i][j] && j - i + 1 > maxLen) {
                    maxLen = j - i + 1;
                    begin = i;
                }
            }
        }
        return s.substring(begin,begin + maxLen);
    }

}
